# -*- coding:utf-8 -*-

from rest_framework.viewsets import ModelViewSet

from Apps.UiTest.filters.uiTestCatFilter import UiTestCatFilter
from Apps.UiTest.models import UiTestCat
from Apps.UiTest.ser.uiTestCat import UiTestCatSer
from Apps.common.response import SuccessResponse
from Apps.util.get_tree import get_tree
import logging

logger = logging.getLogger("django")


class UiTestCatView(ModelViewSet):
    queryset = UiTestCat.objects.all()
    serializer_class = UiTestCatSer
    filter_class = UiTestCatFilter

    # authentication_classes = []

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)

        # 获取所有的模块项
        source_list = [dict(item) for item in serializer.data]

        return SuccessResponse(get_tree(source_list))
